package Arrays101.Day06;

public class Day06_1 {
    public static void main(String[] args) {
        int i = heightChecker(new int[]{5,1,2,3,4});
        System.out.println(i);
    }

    /**
     * Height Checker
     * 求排序后的高度跟之前的高度同位置下有几个不相同
     * @param heights
     * @return
     */
    public static int heightChecker(int[] heights) {
        int[] ints = new int[heights.length];
        int num=0;
        for (int i = 0; i < heights.length ; i++) {
            ints[i]=heights[i];
        }
        for (int i = 0; i < heights.length; i++) {
            for (int j = 0; j < heights.length-i-1; j++) {
                int temp=0;
                if (heights[j]>heights[j+1]){
                    temp=heights[j];
                    heights[j]=heights[j+1];
                    heights[j+1]=temp;
                }
            }
        }
        for (int i = 0; i < heights.length; i++) {
            if (heights[i]!=ints[i]){
                num++;
            }
        }
        return num;
    }
}
